package thinkingInJava.Exception_;

//: exceptions/ExceptionMethods.java
//Demonstrating the Exception Methods.
import static java.lang.System.out; // 静态导入包,可以导入静态方法,省写一些代码

public class ExceptionMethods {
public static void main(String[] args) {
 try {
   throw new Exception("My Exception");
 } catch(Exception e) {	// 使用 Exception （编程相关异常的基类）可以截获所有的异常，所以这个最好放在异常列表的最后面
   out.print("Caught Exception");
   out.print("getMessage():" + e.getMessage());
   out.print("getLocalizedMessage():" +
     e.getLocalizedMessage());
   out.print("toString():" + e);
   out.print("printStackTrace():");
   e.printStackTrace(System.out);
 }
}
} /* Output:
Caught Exception
getMessage():My Exception
getLocalizedMessage():My Exception
toString():java.lang.Exception: My Exception
printStackTrace():
java.lang.Exception: My Exception
     at ExceptionMethods.main(ExceptionMethods.java:8)
*///:~

